package com.prs.crm.action.approval;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.approval.Process;
import com.prs.crm.domain.approval.ProcessType;
import com.prs.crm.domain.approval.ShenQingType;
import com.prs.crm.service.approval.ProcessService;
import com.prs.crm.service.approval.ProcessTypeService;

public class ProcessAction extends BaseAction{
	private ProcessService processService;
	private Process process;
	private PaginationSupport pagination;
	private Integer[] ids;
	private ProcessTypeService processTypeService;
	private List<ProcessType> processTypes;
	public ProcessService getProcessService() {
		return processService;
	}
	public void setProcessService(ProcessService processService) {
		this.processService = processService;
	}
	public Process getProcess() {
		return process;
	}
	public void setProcess(Process process) {
		this.process = process;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public ProcessTypeService getProcessTypeService() {
		return processTypeService;
	}
	public void setProcessTypeService(ProcessTypeService processTypeService) {
		this.processTypeService = processTypeService;
	}
	public List<ProcessType> getProcessTypes() {
		return processTypes;
	}
	public void setProcessTypes(List<ProcessType> processTypes) {
		this.processTypes = processTypes;
	}
	//////////////////////////////////////////////////////////////////////////////////
	@Action("listProcess")
	public String listProcess(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(Process.class);
		this.setPagination(this.processService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("editProcess")
	public String editProcess(){
		this.processTypes = this.processTypeService.getAll();
		return SUCCESS;
	}
	@Action(value="saveProcess",results={
			@Result(name = "success", type = "redirect", location = "listProcess"),
			@Result(name = "error", type = "chain", location = "editProcess")
	})
	public String saveProcess(){
		this.processService.save(process);
		return SUCCESS;
	}
	@Action(value="removeProcess",results={
			@Result(name = "success", type = "redirect", location = "listProcess"),
			@Result(name = "error", type = "chain", location = "listProcess")
	})
	public String delProcess(){
		if(ids == null){
			this.setPrompt("请选择一行！");
			return ERROR;
		}
		this.processService.batchRemove(ids);
		return SUCCESS;
	}
}
